<h4 class="h4"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>&nbsp;添加试题</h4>
<form class="layui-form" action="comm/addquestions.php" name="editForm" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">课程名称</label>
        <div class="layui-input-block">
            <input type="text" name="cname" required  placeholder="课程名称" autocomplete="off"
                disabled value="<?=$row['cname']?>" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">试题类型</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="aihao"  lay-verify="type">
                <option value="单选">单选</option>
                <option value="多选">多选</option>
                <option value="简答">简答</option>
                <option value="应用题">应用题</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">难度</label>
        <div class="layui-input-block">
            <input type="number" name="difficulty" lay-verify="difficulty" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">题干</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="stem" lay-verify="stem"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">正确答案</label>
        <div class="layui-input-block">
            <input type="text" name="resourcesinfo" lay-verify="resourcesinfo" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">考点</label>
        <div class="layui-input-block">
            <input type="text" name="points" lay-verify="points" autocomplete="off" class="layui-input">
        </div>
    </div>

    <input type="hidden" name="sid" value="<?=$sid?>">


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<style>
    .file {
        display: flex;
        justify-content: center;
    }
</style>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        form.verify({
            type: function (value, item) { //value：表单的值、item：表单的DOM对象
               if(!value){
                   return "试题类型不能为空"
               }
            },
            difficulty:(value, item)=>{
                if(!value){
                   return "试题难度不能为空"
               }
               if(parseInt(value)<0||parseInt(value)>5){
                   return "试题难度应该为0~5"
               }
            },
            stem(value, item){
                if(!value){
                    return "题干不能为空"
                }
                if(value.length<5||value.length>400){
                    return "题干长度应该为5~400"
                }
            },
            resourcesinfo(value, item){
                if(!value){
                    return "正确答案不能为空"
                }
            }
            ,points(value, item){
                if(!value){
                    return "考点不能为空"
                }
            }
        });
    });
    $(".newspic").click(function () {
        $(this).next('input').click();
    });


</script>